﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class public_page_user_password_change : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {

            SysCommon.checkUserLogin();

            this.BtnOK.Attributes.Add("onclick", "return check_submit()");
        }
    }



    protected void BtnOK_Click(object sender, EventArgs e)
    {
        try
        {

            if (SysCommon.ProcessSqlStr(this.Txt_user_password.Text).Length == 0)
            {
                SysCommon.JavaScript.alert("请输入原密码！");
                return;
            }

            if (SysCommon.ProcessSqlStr(this.Txt_user_password_new1.Text).Length == 0)
            {
                SysCommon.JavaScript.alert("请输入新密码！");
                return;
            }

            if (this.Txt_user_password_new1.Text != this.Txt_user_password_new2.Text)
            {
                SysCommon.JavaScript.alert("两次新密码输入不正确！");
                return;
            }


            string user_password_old = Convert.ToString(DataBaseOperate_SQLServer.GetValue("select user_password from t_user where user_id=" + SysCommon.ProcessSqlStr(Session["user_id"])));

            if (user_password_old != this.Txt_user_password.Text)
            {
                SysCommon.JavaScript.alert("原密码输入不正确！");
                return;
            }
         
            System.Text.StringBuilder sbstr = new System.Text.StringBuilder(200);
            sbstr.Append("update t_user set user_password='" + SysCommon.ProcessSqlStr(this.Txt_user_password_new1.Text) + "' where user_id=" + SysCommon.ProcessSqlStr(Session["user_id"]));


            DataBaseOperate_SQLServer.ExecUpdate(sbstr.ToString());

            Response.Redirect("user_toIndex.aspx");

        }
        catch (Exception ex)
        {
            Log.Record(ex);
        }



    }


}
